export function getOprateDisable(type) {
  const { location: { pathname = "" }, menuDataList, resourceList } = this.props;
  const res = this.getPageOperate(type, pathname, menuDataList, resourceList);
  return res;
};

function checkStatus(selectedProcesses, statuses, linkStatus) {
  const process = selectedProcesses || [];
  if (process.length === 0) {
    return false;
  }
  let statusArr = statuses;
  if (!statusArr.reduce) {
    statusArr = [statuses];
  }
  const statusMap = statusArr.reduce((m, s) => {
    m[s] = true;
    return m;
  }, {});
  const linkStatusMap = linkStatus.reduce((m, s) => {
    m[s] = true;
    return m;
  }, {});
  return process.every(p => statusMap[p.status] && linkStatusMap[p.linkStatus]);
}

export function getBtnProps(cn, disableClassName, selectedProcesses) {
  const suspendEnabled = this.getOprateDisable("suspend"); // 挂起实例
  const activeEnabled = this.getOprateDisable("active"); // 激活(解挂)实例
  // const jumpEnabled = this.getOprateDisable("jump"); // 任务跳转
  const recallEnabled = this.getOprateDisable("recall"); // 流程撤单
  const endEnabled = this.getOprateDisable("end"); // 流程终止
  const upgradeEnabled = this.getOprateDisable("upgrade"); // 流程转办
  // const deleteEnabled = this.getOprateDisable("delete"); // 流程删除
  const suspendDisabled = !(suspendEnabled && checkStatus(selectedProcesses, ["NORMAL", "WARNING", "TIMEOUT"], ["RUNNING"]));
  const activeDisabled = !(activeEnabled && checkStatus(selectedProcesses, "PAUSE", ["RUNNING"]));
  const recallDisabled = !(recallEnabled && checkStatus(selectedProcesses, ["NORMAL", "WARNING", "TIMEOUT"], ["RUNNING","START"]));
  const endDisabled = !(endEnabled && checkStatus(selectedProcesses, ["NORMAL", "WARNING", "TIMEOUT"], ["RUNNING","START"]));
  const upgradeDisabled = !(upgradeEnabled && checkStatus(selectedProcesses, ["NORMAL", "WARNING", "TIMEOUT"], ["RUNNING","START"]));
  // const deleteDisabled = !(deleteEnabled && checkStatus(selectedProcesses, ["NORMAL", "WARNING", "TIMEOUT"], ["RUNNING","START"]));
  return [
    {
      className: `${cn} ${activeDisabled ? disableClassName : ""}`,
      children: "解挂",
      key: "0",
      onClick: () => {
        if (activeDisabled) {
          return;
        }
        this.handleDealFormVisible(true, null, "解挂处理", "UNPAUSE");
      },
    },
    {
      className: `${cn} ${suspendDisabled ? disableClassName : ""}`,
      children: "挂起",
      key: "1",
      onClick: () => {
        if (suspendDisabled) {
          return;
        }
        this.handleDealFormVisible(true, null, "挂起处理", "PAUSE");
      },
    },
    {
      className: `${cn} ${recallDisabled ? disableClassName : ""}`,
      children: "撤单",
      key: "2",
      onClick: () => {
        if (recallDisabled) {
          return;
        }
        this.handleDealFormVisible(true, null, "撤单处理", "RECALL");
      },
    },
    {
      className: `${cn} ${endDisabled ? disableClassName : ""}`,
      children: "终止",
      key: "3",
      onClick: () => {
        if (endDisabled) {
          return;
        }
        this.handleDealFormVisible(true, null, "终止处理", "END");
      },
    },
    {
      className: `${cn} ${upgradeDisabled ? disableClassName : ""}`,
      children: "升版",
      key: "4",
      onClick: () => {
        if (upgradeDisabled) {
          return;
        }
        this.handleDealFormVisible(true, null, "迁移至最新版本", "UPGRADE");
      },
    },
    // {
    //   className: `${cn} ${deleteDisabled ? disableClassName : ""}`,
    //   children: "删除",
    //   key: "4",
    //   onClick: () => {
    //     if (deleteDisabled) {
    //       return;
    //     }
    //     this.handleDealFormVisible(true, null, "删除处理", "DELETE");
    //   },
    // },
  ];
}
